package com.catmiw.swt;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

public abstract class BasicWindow {
	protected Display display;
	protected Shell shell;
	
	public BasicWindow(){
		display = Display.getDefault();
		shell = new Shell(display);	
		shell.setSize(800, 600);
		shell.setLocation(display.getClientArea().width / 2 - shell.getSize().x/2, display
                .getClientArea().height / 2 - shell.getSize().y/2);

		shell.setText("SWT Example");
	}

	public void open() {
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}
	
	public int messagebox(String title,String message){
		MessageBox mb=new MessageBox(shell);
		mb.setText(title);
		mb.setMessage(message);
		return mb.open();
	}
	
	public abstract void createContents();
}
